package org.bigwinner.flinkLearning.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Properties;


/**
 * @author: IT大狮兄
 * @date: 2021/7/31 下午10:16
 * @version: 1.0.0
 * @description: 配置文件工具类
 */
public class ConfigFileUtils {
    private static final Logger LOGGER = LoggerFactory.getLogger(ConfigFileUtils.class);
    private static Properties properties;


    static {
        URL resource = ConfigFileUtils.class.getResource("/");
        InputStream input = null;
        if (null != resource) {
            LOGGER.info("Loading config.properties, classPath = {}", resource.getPath());
            try {
                properties = new Properties();
                input = ConfigFileUtils.class.getClassLoader().getResourceAsStream("config.properties");
                properties.load(input);
                LOGGER.info("Properties init finished! properties: {}", properties);
            } catch (Exception e) {
                LOGGER.error("Loading config.properties fails, cause = ", e);
            } finally {
                try {
                    if (null != input) input.close();
                } catch (IOException e) {
                    LOGGER.error("inutStream close error: {}", e);
                }
            }
        } else {
            LOGGER.error("config.properties file does not exists, please check you config file!!!");
        }
    }
    public static String getValue(String key) {
        return properties.getProperty(key);
    }

    public static void main(String[] args) {

        System.out.println(ConfigFileUtils.getValue("mysql.driver"));
    }
}
